<?php
App::uses('AppController', 'Controller');
/**
 * MateriasNiveles Controller
 *
 * @property MateriasNivele $MateriasNiveles
 */
class MateriasNivelesController extends AppController {

    public $uses = array('MateriasNivele','Materia');
    public $layout = 'colegio';
    
    public function beforeFilter()
    {
        parent::beforeFilter();
        $this->Auth->allow('*');
    }
    
    public function index(){
        $materiasNiveles = $this->MateriasNivele->find('all', array(
            'recursive'=>0           
            ));
        $this->set(compact('materiasNiveles'));
    }
    
    public function listamaterias($idNivel = null){
        
        $materiasNiveles = $this->MateriasNivele->find('all', array(
            'recursive'=>0,
            'conditions'=>array('MateriasNivele.nivele_id' => $idNivel)
        ));
        //debug($materiasNiveles);exit;
        $this->set(compact('materiasNiveles', 'idNivel'));
    }
    
    public function eliminarmateria($idMat = null, $idNivel = null){
                
        $this->MateriasNivele->id = $idMat;
        $this->data = $this->MateriasNivele->read();
        if (!$idMat)
        {
            $this->Session->setFlash('No existe la Materia Nivel  a eliminar');
            $this->redirect(array('controller'=>'MateriasNiveles', 'action' => 'listamaterias'));
        } else
        {
            if ($this->MateriasNivele->delete($idMat))
            {
                $this->Session->setFlash('Se elimino el Tag ', 'msgbueno');
                $this->redirect(array('controller'=>'MateriasNiveles', 'action' => 'listamaterias', $idNivel));
            } else
            {
                $this->Session->setFlash('Error al eliminar');
            }
        }    
            
    }
    
    
        function insertar(){
        if(!empty($this->data)){
            if($this->MateriasNivele->save($this->data)){
                $this->Session->setFlash('Se Guardo Correctamente!!!');
                $this->redirect(array('action'=>'index')); 
                }
            else{
                $this->Session->setFlash('Error al Guardar consulte con el Administrador de Sistema');
            }
        }
        
    }
    

    
}